package data;

import exception.ExceptionConnection;
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author BACQ Justine et SACRE Sauvane
 */

public class MySingleton {
    private static Connection uniqueInstance; 
    private MySingleton(){}
    
    public static Connection getInstance() throws ExceptionConnection{
        if(uniqueInstance == null){
            try{
                Context ctx = new InitialContext();
                DataSource source = (DataSource) ctx.lookup("jdbc/spa");
                uniqueInstance = source.getConnection(); 
            } catch (Exception ex){
                throw new ExceptionConnection(); 
            }
        }
        return uniqueInstance; 
    }
}
